<?php
session_start();

$settings = array("site_name" => "Site Name",
                  "base_url" => "http://localhost/",
                  "version" => "10001");
                  
$lib_files = listdir('inc', 'php'); 

//Class autoloading
function __autoload($class_name) {
  global $lib_files;
  $file = strtolower($class_name) . '.php';
  $keys = array_keys($lib_files);
  if (in_array($file, $keys)){
    require_once $lib_files[$file];
  }
  
}

//some helper functions
function listdir($dir='.', $ext=false) { 
    if (!is_dir($dir)) { 
        return false; 
    } 
    
    $files = array(); 
    listdiraux($dir, $files, $ext); 

    return $files; 
} 

function listdiraux($dir, &$files, $ext=false) { 
    $handle = opendir($dir); 
    while (($file = readdir($handle)) !== false) { 
        if ($file == '.' || $file == '..') { 
          continue; 
        } 
        $filepath = $dir == '.' ? $file : $dir . '/' . $file; 
        if (is_link($filepath)) 
          continue; 
        if (is_file($filepath)) {
          if ($ext!=false){
            $extension = end(explode('.',$filepath));
            if ($extension == $ext)
              $files[$file] = $filepath; 
            continue;
          } 
          $files[] = $filepath; 
        }else if (is_dir($filepath)) {
          listdiraux($filepath, $files, $ext); 
        }
          
    } 
    closedir($handle); 
} 

?>